package com.eastfair.venueservice.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.boot.service.SuperService;
import com.eastfair.venueservice.dto.ExhibitionSettlementDTO;
import com.eastfair.venueservice.dto.ViolationRecordDTO;
import com.eastfair.venueservice.entity.ViolationRecord;
import com.eastfair.venueservice.vo.ExhibitionSettlementVO;
import com.eastfair.venueservice.vo.ViolationRecordVO;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 业务接口
 * 违规处罚记录
 * </p>
 *
 * @author lyw
 * @date 2022 -08-11
 */
public interface ViolationRecordService extends SuperService<ViolationRecord> {

    /**
     * 查询违规惩罚记录列表分页
     *
     * @param params the params
     * @return page
     */
    Page<ViolationRecordVO> queryViolationRecordList(PageParams<ViolationRecordDTO> params);


    /**
     * 根据被监督者的id查询数据
     *
     * @param id
     * @return
     */
    List<ViolationRecordVO> getViolationRecordListById(Long id);

    /**
     * 查询违规惩罚记录详情
     *
     * @param violationRecordDTO the violation record dto
     * @return violation record vo
     */
    ViolationRecordVO getViolationRecord(ViolationRecordDTO violationRecordDTO);

    /**
     * 查询违规记录列表.
     *
     * @param query the violation record dto
     * @return the list
     */
    List<ViolationRecord> listViolationRecord(ViolationRecordDTO query);

    /**
     * 展会ID，服务商ID查询场馆的违规记录
     *
     * @param exhibitionManageId the exhibition manage id
     * @param supervisedId  the service provider id
     * @return the list
     */
    List<ViolationRecord> listByExhibitionManageId(Long exhibitionManageId, Long supervisedId);

    /**
     * 展商ID查询主场违规记录
     *
     * @param exhibitorId the exhibitor id
     * @return the list
     */
    List<ViolationRecord> listByExhibitorId(Long exhibitorId);

    /**
     * 布撤展管理记录ID查询主场巡检的未取消违规记录.
     *
     * @param arrangementId the arrangement id
     * @return the list
     */
    List<ViolationRecord> listHomeCheckViolationRecordByArrangementId(Long arrangementId);

    /**
     * 查询待结算的场馆下发的违规记录
     *
     * @param query the query
     * @return the list
     */
    List<ViolationRecordVO> listForVenueViolationRecordSettlement(ViolationRecordDTO query);

    /**
     * 获取主场下发的违规的结算单
     *
     * @param query the query
     * @return the venue violation record settlement
     */
    ExhibitionSettlementVO getHomeViolationRecordSettlement(ExhibitionSettlementDTO query);

    /**
     * 查询待结算的主场下发的违规记录
     *
     * @param query the query
     * @return the list
     */
    List<ViolationRecordVO> listForHomeViolationRecordSettlement(ViolationRecordDTO query);

    /**
     * 获取场馆下发的违规的结算单
     *
     * @param query the query
     * @return the venue violation record settlement
     */
    ExhibitionSettlementVO getVenueViolationRecordSettlement(ExhibitionSettlementDTO query);

    /**
     * 保存违规记录.
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    ViolationRecord saveViolationRecord(ViolationRecordDTO violationRecordDTO);

    /**
     * 主场生成违规惩罚记录
     *
     * @param violationRecordDTO the violation record dto
     * @return boolean
     */
    boolean saveForHome(ViolationRecordDTO violationRecordDTO);

    /**
     * 场馆巡检生成违规惩罚记录
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    boolean saveForVenue(ViolationRecordDTO violationRecordDTO);

    /**
     * 场馆巡检生产证件违规惩罚记录.
     *
     * @param violationRecordDTO the violation record dto
     * @return the violation record
     */
    ViolationRecord saveFoVenueCheckCertificate(ViolationRecordDTO violationRecordDTO);

    /**
     * 修改违规惩罚记录
     *
     * @param violationRecordDTO the violation record dto
     * @return boolean
     */
    boolean updateViolationRecord(ViolationRecordDTO violationRecordDTO);

    /**
     * 更新场馆违法扣款
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    boolean updateVenuePunishAmount(ViolationRecordDTO violationRecordDTO);

    /**
     * 更新主场处罚扣款.
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    boolean updateHomePunishAmount(ViolationRecordDTO violationRecordDTO);

    /**
     * 更新处罚扣款.
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    ViolationRecord updatePunishAmount(ViolationRecordDTO violationRecordDTO);

    /**
     * 支付处罚扣款.
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    @Deprecated
    boolean payPunishAmount(ViolationRecordDTO violationRecordDTO);

    /**
     * 保存交易记录.
     *
     * @param violationRecord    the violation record
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    boolean saveTransaction(ViolationRecord violationRecord, ViolationRecordDTO violationRecordDTO);

    /**
     * 保存支付系统交易订单.
     *
     * @param violationRecordDTO the violation record dto
     * @return the boolean
     */
    boolean saveTransactionOrder(ViolationRecordDTO violationRecordDTO);

    /**
     * 保存支付系统交易订单.
     *
     * @param id the id
     * @return the boolean
     */
    boolean saveTransactionOrder(Long id);

    /**
     * 撤销处罚.
     *
     * @param id the violation record dto
     * @return the boolean
     */
    boolean cancelHomeViolationRecord(Long id);

    /**
     * 删除违规惩罚记录
     *
     * @param id the id
     * @return boolean
     */
    boolean delViolationRecord(Long id);

    /**
     * 发送配置收款商户的站内信.
     *
     * @param violationRecordDTO the violation record dto
     * @return the r
     */
    boolean sendConfigPayeeInnerMsg(ViolationRecordDTO violationRecordDTO);

    /**
     * 异步发送配置收款商户的站内信.
     *
     * @param violationRecordDTO the violation record dto
     */
    void asyncSendConfigPayeeInnerMsg(ViolationRecordDTO violationRecordDTO);

    /**
     * 计算违规罚款的结算单
     *
     * @param violationRecordList the violation record list
     * @return the exhibition settlement vo
     */
    static ExhibitionSettlementVO calculateExhibitionSettlement(List<ViolationRecordVO> violationRecordList) {
        ExhibitionSettlementVO exhibitionSettlementVO = new ExhibitionSettlementVO();
        BigDecimal violationPunish = BigDecimal.ZERO;
        for (ViolationRecordVO violationRecordVO: violationRecordList) {
            BigDecimal shouldPunishAmount = violationRecordVO.getShouldPunishAmount() == null ? BigDecimal.ZERO : violationRecordVO.getShouldPunishAmount();
            violationPunish = violationPunish.add(shouldPunishAmount);
        }
        exhibitionSettlementVO.setViolationPunish(violationPunish);
        return exhibitionSettlementVO;
    }

}
